package utils

import (
	"fmt"
	"os"
	"os/exec"
	"runtime"
	"strings"
)

func GetOS() string {
	// 先尝试通过环境变量获取
	if envOS := os.Getenv("OSTYPE"); envOS != "" {
		return envOS
	}

	// 再通过runtime包获取
	os := runtime.GOOS

	return os
}

func Execs(text string) {
	cmds := strings.Split(text, " ")
	if GetOS() == "windows" {
		cmds = append([]string{"cmd", "/c"}, cmds...)
	}
	cmd := exec.Command(cmds[0], cmds[1:]...)
	if cmd.Err != nil {
		fmt.Println(cmd.Err)
		return
	}
	output, err2 := cmd.Output()
	if err2 != nil {
		fmt.Println(cmd)
		return
	}
	fmt.Println(string(output))

}
